// 创建crypto.js
var express = require('express')
var crypto = express.Router()// 创建一个路由实例

// 中间件功能
crypto.use(function timeLog(req, res, next) {
  console.log('Time: ', new Date().toLocaleString())
  next()
})

crypto.post('/cryptoTest', function (req, res) {
  console.log('zdy-----headers：------>' + JSON.stringify(req.headers))
  console.log('zdy-----path------>' + JSON.stringify(req.path))
  console.log('zdy-----baseUrl------>' + JSON.stringify(req.baseUrl))
  let requestPath = ''
  if (req.baseUrl != undefined && req.baseUrl != '' && req.baseUrl != null && req.baseUrl.trim().length > 0) {
    requestPath = req.baseUrl
  } else if (req.path != undefined && req.path != '' && req.path != null && req.path.trim().length > 0) {
    requestPath = req.path
  }
  let requestUrl = ''
  if ('http' === req.protocol) {
    requestUrl = 'http://' + req.hostname + requestPath
  } else {
    requestUrl = 'https://' + req.hostname + requestPath
  }
  console.log('zdy-----requestUrl------>' + requestUrl)

 console.log('zdy-----body------>' + JSON.stringify(req.body))

  res.json(req.body)
})

module.exports = crypto